var phonereg = /^(((1[0-9]{1}))+\d{9})$/;
var mailreg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


;(function($){
    $(document).ready(function($){
        var $jscrollpane = $('[data-toggle="jscrollpane"]');
        $jscrollpane.each(function(i, el){
            var $self = $(this),
                options = $self.data();
            $self.jScrollPane(options);
        });
    });

})(window.jQuery);


$(document).ready(function (){

    //导航事件
    window.headhover = function (){
    };

    window.claheadhover = function (){
    };

    //录取啦登录
    //var $luqulabtn = $('.js-log-luqula');
    $(document).on('click', '.js-log-luqula', function (){
        var uprotocol = $.url().attr('protocol');
        var uhost = $.url().attr('host');
        var udirectory = $.url().attr('directory');
        var successurl = uprotocol + '://' + uhost + udirectory + 'stu_index.html';

        var sendurl = "http://test-l.hfjy.com/oauth/authorize?client_id=hls_client&response_type=code&redirect_uri=" + successurl;
        window.open(sendurl);
    });


    $(document).on('click', '.phone-close', function (){
        $('.bind-phone').hide();
    });

    //登录注册按钮
    $(document).on("click",".login-log",function(){
        $(".loginBox").show();
        $(".signBox").hide();
        $(".studentLogin").addClass("animated down").fadeIn();
        window.otherlogin();
    });
    $(document).on("click",".login-reg",function(){
        $(".signBox").show();
        $(".loginBox").hide();
        $(".studentLogin").addClass("animated down").fadeIn();
        window.otherlogin();
    });


    //检查绑定手机号
    window.checkPhoneBind = function (){
        var luqulacode = $.url().param('code');
        if(luqulacode != '' && luqulacode != undefined){
            //获取登录状态
            $.ajax({
                url: '../../user/checkPhoneBindingOrNot',
                type: 'post',
                dataType: 'json',
                async: false,
                data: {
                    'code': luqulacode
                },
                success: function (data) {
                    console.log(data);
                    var e_code = data.code;
                    if(e_code == 0){
                        var e_phone = data.data.phone;
                        $('.bind-phone').show();

                        if(e_phone != "" || e_phone != undefined){
                            window.bind_text_phone = e_phone;
                            var firstphone = window.bind_text_phone.substr(0, 3);
                            var lastphone = window.bind_text_phone.substr(7, 4);
                            var txtphone = firstphone + " **** " + lastphone;
                            $('.js-txt-bind-phone').attr('disabled', 'disabled').addClass('unlink').val(txtphone);
                            bindGetCode(false);
                        }else{
                            bindGetCode(true);
                        }

                    }else if(e_code == 1){
                        $('.bind-phone').hide();
                        location.reload();
                    }else if(e_code == -1){
                        $('.bind-phone').hide();
                    }
                }
            });
        }
    };

    //绑定手机获取验证码事件
    var bindGetCode = function (e_isbind){
        var $getCode = $('.js-btn-get-code');
        $getCode.on('click', function (){
            var $phone = $('.js-txt-bind-phone');
            var txt_phone = '';
            if(e_isbind){
                txt_phone = $.trim($phone.val());
            }else{
                txt_phone = window.bind_text_phone;
            }
            if(txt_phone == '' || !txt_phone.match(phonereg)){
                HFErrorShow.inputWrong(".js-txt-bind-phone", '请输入正确的手机号');
            }else{
                $('.errorspan').remove();
               var resouse = window.getCode(txt_phone);
                if(resouse.code == 1){
                    bindPhoneCoundDown(60, $('.js-btn-get-code'), e_isbind);
                }else{
                    HFErrorShow.inputWrong(".js-txt-bind-phone", resouse.desc);
                }
            }
        });

        var $txt_code = $('.js-txt-bind-code');
        var $phonebinding = $('.js-bindingphone');
        var codeIntval;
        $txt_code.on('keypress', function (){
            clearInterval(codeIntval);
            var $self = $(this);
            codeIntval = setTimeout(function (){
                var $binding = $('.js-bindingphone');
                var txtcode = $.trim($self.val());

                if(txtcode != '' && txtcode != undefined){
                    $binding.removeClass('unlink');
                    $phonebinding.off('click').on('click', function (){

                        var e_phone = window.bind_text_phone;
                        if(e_phone == '' || e_phone == undefined){
                            e_phone = $.trim($('.js-txt-bind-phone').val());
                        }else{
                            e_phone = window.bind_text_phone;
                        }
                        var e_code = $.trim($('.js-txt-bind-code').val());
                        phoneBindEvent(e_phone, e_code);
                    });
                }else{
                    $binding.addClass('unlink');
                    $phonebinding.off('click');
                }
            }, 200);
        });

        var phoneBindEvent = function (e_phone, e_code){
            $.ajax({
                url:'../../user/bindingPhoneToHls',
                type:'post',
                data: {
                    'phone': e_phone,
                    'registerCode': e_code
                },
                async: false,
                dataType:'json',
                success:function (data){
                    if(data.code == 1){
                        var uprotocol = $.url().attr('protocol');
                        var uhost = $.url().attr('host');
                        var udirectory = $.url().attr('directory');
                        var file = $.url().attr('file');
                        location.href = uprotocol + '://' + uhost + udirectory + file;
                    }else{
                        HFErrorShow.inputWrong(".js-txt-bind-code", data.desc);
                    }
                }
            });
        };
    };

    //获取验证码
    window.getCode = function (e_phone){
        var resouse = {};
        $.ajax({
            url:'../../user/sendCodeForThirdPartyLogin',
            type:'post',
            data: {
                'phone':e_phone
            },
            async: false,
            dataType:'json',
            success:function (data){
                resouse = data;
            }
        });
        return resouse;
    };
//获取验证码
    window.getCode2 = function (e_phone){
        var resouse = {};
        $.ajax({
            url:'../../user/sendVerifyCodeForRegister',
            type:'post',
            data: {
                'phone':e_phone
            },
            async: false,
            dataType:'json',
            success:function (data){
                resouse = data;
            }
        });
        return resouse;
    };

    //验证绑定手机
    //http://test-l.hfjy.com/oauth/www.hfjy.com/html/stu_index.html?code=2A37208295BC38ACA012119BF542EA7B
    var urlIsTrue = $.isFunction($.url);
    if(urlIsTrue){
        window.checkPhoneBind();
    }else{
        $.getScript('./libs/purl/2.3.1/purl.js', function (){
            window.checkPhoneBind();
        });
    }

    //验证登录
    window.tokenMatching = function() {

        $(".sign").on('click',function(){
            $(".dias").remove();
            $(".signBox").show();
            $(".loginBox").hide();
        });
        $(".login-text").on('click',function(){
            $(".dias").remove();
            $(".loginBox").show();
            $(".signBox").hide();
        });

        //获取登录状态
        $.ajax({
            url: '../../user/getUserInfo',
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                var uname = data.data.name;
                if (typeof(uname) == "undefined" || uname == "") {
                    var utoken = $.cookie("tokenCode");
                    if(utoken != null){
                        var phone = $.cookie("uname");
                        $.ajax({
                            url: '../../user/rememberLoginStatus',
                            type: 'post',
                            data: {'phone': phone, 'tokenCode': utoken},
                            async: false,
                            dataType: 'json',
                            success: function (tdata) {
                                if(tdata.code == 1){
                                    $.cookie("tokenCode", tdata.data.tokenCode, {expires: 30});
                                    $(".login-ago").hide();
                                    $(".logined").show();
                                    console.log(tdata.data.userName);
                                    $(".logined .uname").text(tdata.data.userName);
                                    window.userhover();
                                }
                            }
                        });
                    }
                }else {
                    $(".login-ago").hide();
                    $(".logined").show();
                    $(".logined .uname").text(uname);
                    window.userhover();
                }
            }
        });

    };

    window.userhover = function (){
        //登录后划过
        $(".uname").mouseenter(function (){
            var $logined = $(".uname");
            var $selong = $("#selong");
            var llf = $logined.offset().left;
            var lwd = $logined.width();
            var lfs = llf - (lwd / 2);
            var hg = $('.logined').height();
            var tps = hg/2;
            $selong.css({'position': "fixed", 'left': lfs + "px", 'top': tps + "px"}).show();
        });

        //点击其余部分关闭
        $(document).mouseover(function(e){
            var _con = $('#selong,.uname');   // 设置目标区域
            var isPc = window.fn_isPC();
            if(!_con.is(e.target) && _con.has(e.target).length === 0 && isPc){ // Mark 1
                $("#selong").hide();
            }
        });

        //退出
        $(".exits").on("click", function () {
            $.ajax({
                url: '../../user/exit',
                type: 'post',
                dataType: 'json',
                async: false,
                success: function (resouse) {
                	$("#selong").hide();
                    $.cookie("tokenCode", null);
                    location.reload(location.href);
                }
            });
        });
    };

    window.islogin = function (){
        //获取登录状态
        $.ajax({
            url: '../../user/getUserInfo',
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                var uname = data.data.name;
                if (typeof(uname) == "undefined" || uname == "") {
                    location.href = "stu_index.html";
                }
            }
        });
    };

    window.fn_isPC = function () {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    };

    window.teaislogin = function (){
        //是否登录
        $.ajax({
            url: '../../user/getUserInfo',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                var uname = data.data.name;
                if (typeof(uname) == "undefined" || uname == "") {
                    location.href = 'tea_login.html';
                }
            }
        });
    };


});


//cookie 操作
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


//数字限定1
var fn_onlyInputNumber_One = function (e){
    var isIE = false;
    var isFF = false;
    var isSa = false;
    if ((navigator.userAgent.indexOf("MSIE") > 0)
        && (parseInt(navigator.appVersion) >= 4))
        isIE = true;
    if (navigator.userAgent.indexOf("Firefox") > 0)
        isFF = true;
    if (navigator.userAgent.indexOf("Safari") > 0)
        isSa = true;
    var key;

    var iKeyCode = window.event ? e.keyCode : e.which;
    if (!(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13)
        || (iKeyCode == 46) || (iKeyCode == 45) || (iKeyCode == 37)
        || (iKeyCode == 39) || (iKeyCode == 8)))
    {
        if (isIE) {
            e.returnValue = false;
        } else {
            e.preventDefault();
        }
    }
};

//数字限定2
var fn_onlyInputNumber_Two = function (e, val){
    var isIE = false;
    var isFF = false;
    var isSa = false;
    if ((navigator.userAgent.indexOf("MSIE") > 0)
        && (parseInt(navigator.appVersion) >= 4))
        isIE = true;
    if (navigator.userAgent.indexOf("Firefox") > 0)
        isFF = true;
    if (navigator.userAgent.indexOf("Safari") > 0)
        isSa = true;

    var key;
    var iKeyCode = window.event ? e.keyCode : e.which;
    if (!(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13)
        || (iKeyCode == 46) || (iKeyCode == 8)))
    {
        if (isIE) {
            e.returnValue = false;
        } else {
            e.preventDefault();
        }
    }
    var char_str = val.split("");
    var k = 0;
    for(var i=0;i<char_str.length;i++){
        if(char_str[i] == '.') k++;
    }
    if(k > 0 && (iKeyCode == 46)){
        if (isIE) {
            e.returnValue = false;
        } else {
            e.preventDefault();
        }
    }
    var str = val.split(".");
    if(str[1] != null && str[1].length > 1){
        if (isIE) {
            e.returnValue = false;
        } else {
            e.preventDefault();
        }
    }
};



/*8进制加密*/
function encodeEight(str) {
    var monyer = "";
    for (var i = 0; i < str.length; i++) {
        monyer += "X" + str.charCodeAt(i).toString(8);
    }
    return monyer;
}
/*8进制解密*/
function decodeEight(str) {
    var monyer = "";
    var s = str.split("X");
    for (var i = 1; i < s.length; i++) {
        monyer += String.fromCharCode(parseInt(s[i], 8));
    }
    return monyer;
}

//获取get传值
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

//加密解密
(function (window, undefined) {
    "use strict";
    window.WSY = window.WSY || {};
    var WSY = window.WSY;
    WSY.enCode = function (src) {
        var res;
        res = window.JSON.stringify(src);
        var buff = [];
        for (var i = 0; i < res.length; i++) {
            var bit = res.charCodeAt(i).toString(16);
            buff.push(bit);
        }
        res = buff.join('/');
        res = window.btoa(res);
        return window.encodeURIComponent(res);
    };
    WSY.deCode = function (src) {
        var res, buff, enBit, bit;
        res = window.decodeURIComponent(src);
        res = window.atob(res);
        res = res.split('/');
        buff = [];
        for (var i = 0, len = res.length; i < len; i++) {
            enBit = res[i];
            bit = String.fromCharCode(parseInt(enBit, 16));
            buff.push(bit);
        }
        res = buff.join('');
        res = window.JSON.parse(res);
        return res;
    }
})(window);

var ERRORSHOW = {
    inputWrong : function(obj,outtxt){
        $(".dias").remove();
        var html = "<span class='dias errorspan'>"
            +outtxt
            +"</span>"
        $("body").append(html);
        ERRORSHOW.inWrongResize(obj);

        $(window).on("resize",function(){
            ERRORSHOW.inWrongResize(obj);
        });
    },
    inWrongResize : function(obj){
        var wd = parseInt($(obj).css("width"));
        var hg = parseInt($(obj).css("height"));
        var lf = parseInt($(obj).offset().left);
        var tp = parseInt($(obj).offset().top + hg);
        $(".errorspan").css({
            "display": "inline-block",
            "width": wd + "px",
            "height": "22px",
            "position": "absolute",
            "left": lf +"px",
            "top": tp +"px",
            "color": "#fa5a67",
            "text-align": "center",
            "z-index": "9900",
            "background": "none",
            "font-size": "14px",
            "line-height": "22px"
        });
    }
};


//登录&注册
window.otherlogin = function (){

    //点击其余部分关闭
    $(document).mouseup(function(e){
        var _con;
        if($('.loginBox').css('display') == 'none'){
            _con = $('.signBox');
        }else{
            _con = $('.loginBox');
        }
        //_con = $('.loginBox，.signBox');   // 设置目标区域
        if(!_con.is(e.target) && _con.has(e.target).length === 0){ // Mark 1
            $('.studentLogin').hide();
            $(".dias.errorspan").remove();
        }
    });

    //获取cookie手机号
    if(document.cookie && document.cookie != ''){
        var uname = $.cookie("uname");
        $(".stutxtname").val(uname);
    }

    $("#btnlogin").on('click',function (){
        $(".stutxtname").focus().blur();
        $(".stutxtpass").focus().blur();
        var username = $.trim($(".stutxtname").val());
        var userpass = $.trim($(".stutxtpass").val());
        if(username == "" || (!username.match(phonereg))){
            $(".stutxtname").addClass("txterror wrong");
            $(".stutxtname").focus(function (){
                $(".dias").remove();
                $(".stutxtname").removeClass("txterror wrong");
            });
        }
        if(userpass == ""){
            $(".stutxtpass").addClass("txterror wrong");
            $(".stutxtpass").focus(function (){
                $(".dias").remove();
                $(".stutxtpass").removeClass("txterror wrong");
            });
        }
        if(username == "" || !username.match(phonereg)){
            ERRORSHOW.inputWrong(".stutxtname","请输入正确的手机或邮箱");
        }else if(userpass == ""){
            ERRORSHOW.inputWrong(".stutxtpass","请输入密码");
        }else{
            //验证是否自动登录
            var tag = 0;
            if($("#rememberlog").is(':checked')){
                tag = 1;
            }else{
                tag = 0;
            }
            $.ajax({
                url:'../../user/login',
                type:'post',
                data: {'phone':username,'password':userpass,'tag':tag,'userType':0},
                async: false,
                dataType:'json',
                success:function (resouse){
                    $.cookie('uname',username,{expires:30});
                    if(resouse.code==1){
                        //记录tokenCode
                        if(tag == 1){
                            var tokenCode = resouse.data.tokenCode;
                            $.cookie("tokenCode",tokenCode,{expires:30});
                        }
                        window.userhover();
                        location.href = location.href;
                    }else{
                        $(".stutxtname").addClass("txterror wrong");
                        $(".stutxtname").focus(function (){
                            $(".dias").remove();
                            $(".stutxtname").removeClass("txterror wrong");
                        });
                        $(".stutxtpass").addClass("txterror wrong");
                        $(".stutxtpass").focus(function (){
                            $(".dias").remove();
                            $(".stutxtpass").removeClass("txterror wrong");
                        });
                        ERRORSHOW.inputWrong(".stutxtname",resouse.desc);
                    }
                }
            });
        }
    });

    //获取验证码
    $(".getcode").on("click",function (){
        var $reguphone = $(".reguphone");
        $reguphone.focus().blur();
        var reguphone = $.trim($reguphone.val());

        if(reguphone == "" || !reguphone.match(phonereg)){
            $reguphone.addClass("txterror wrong");
            $reguphone.focus(function (){
                $(".dias").remove();
                $(".reguphone").removeClass("txterror wrong");
            });
            ERRORSHOW.inputWrong(".reguphone","请输入正确的手机号");
        }else{
            var resouse = window.getCode2(reguphone);
            if(resouse.code == 1){
                countDown(60);
            }else{
                ERRORSHOW.inputWrong(".reguphone",resouse.desc);
            }
        }
    });

    //注册验证
    $("#btnreg").click(function (){
        $(".reguname").focus().blur();
        $(".reguphone").focus().blur();
        $(".regupass").focus().blur();
        $(".regrpass").focus().blur();
        $(".regucode").focus().blur();
        var reguname = $.trim($(".reguname").val());
        var reguphone = $.trim($(".reguphone").val());
        var regupass = $.trim($(".regupass").val());
        var regrpass = $.trim($(".regrpass").val());
        var regucode = $.trim($(".regucode").val());
        if(reguphone == "" || !reguphone.match(phonereg)){
            $(".reguphone").addClass("txterror wrong");
            $(".reguphone").focus(function (){
                $(".dias").remove();
                $(".reguphone").removeClass("txterror wrong");
            });
        }
        if(reguname == "" ){
            $(".reguname").addClass("txterror wrong");
            $(".reguname").focus(function (){
                $(".dias").remove();
                $(".reguname").removeClass("txterror wrong");
            });
        }
        if(regupass == ""){
            $(".regupass").addClass("txterror wrong");
            $(".regupass").focus(function (){
                $(".dias").remove();
                $(".regupass").removeClass("txterror wrong");
            });
        }
        if(regrpass == ""){
            $(".regrpass").addClass("txterror wrong");
            $(".regrpass").focus(function (){
                $(".dias").remove();
                $(".regrpass").removeClass("txterror wrong");
            });
        }
        if(regupass != regrpass){
            $(".regrpass").addClass("txterror wrong");
            $(".regrpass").focus(function (){
                $(".dias").remove();
                $(".regrpass").removeClass("txterror wrong");
            });
            $(".regupass").addClass("txterror wrong");
            $(".regupass").focus(function (){
                $(".dias").remove();
                $(".regupass").removeClass("txterror wrong");
            });
        }
        if(regucode == ""){
            $(".regucode").addClass("txterror wrong");
            $(".regucode").focus(function (){
                $(".dias").remove();
                $(".regucode").removeClass("txterror wrong");
            });
        }

        if(reguphone == "" || !reguphone.match(phonereg)){
            ERRORSHOW.inputWrong(".reguphone","请输入正确的手机号");
        }
        else if(reguname == ""){
            ERRORSHOW.inputWrong(".reguname","请输入正确的姓名");
        }
        else if(regupass == ""){
            ERRORSHOW.inputWrong(".regupass","请输入密码");
        }
        else if(regrpass == ""){
            ERRORSHOW.inputWrong(".regrpass","请输入确认密码");
        }
        else if(regupass != regrpass){
            ERRORSHOW.inputWrong(".regupass","两次密码输入不一致");
        }
        else if(regucode == ""){
            ERRORSHOW.inputWrong(".regucode","请输入验证码");
        }
        else{
            $.ajax({
                url:'../../user/regist',
                type:'post',
                data: {
                    'phone':reguphone,
                    'password':regupass,
                    'name':reguname,
                    'age':-1,
                    'sex':-1,
                    'email': "",
                    'areaId':-1,
                    'registerCode': regucode
                },
                dataType:'json',
                success:function (resouse){
                    if(resouse.code == -1){
                        $(".reguphone").addClass("txterror");
                        ERRORSHOW.inputWrong(".reguphone",resouse.desc);
                        $(".reguphone").focus(function (){
                            $(".dias").remove();
                            $(".reguname").removeClass("txterror");
                        });
                    }else if(resouse.code == -2){
                        $(".regupass").addClass("txterror");
                        $(".regrpass").addClass("txterror");
                        ERRORSHOW.inputWrong(".regupass",resouse.desc);
                        $(".regupass").focus(function (){
                            $(".dias").remove();
                            $(".reguname").removeClass("txterror");
                        });
                        $(".regrpass").focus(function (){
                            $(".reguname").removeClass("txterror");
                        });
                    }
                    else if(resouse.code == 1){
                        ERRORSHOW.inputWrong(".reguphone",resouse.desc);
                        $.cookie('uname',reguphone,{expires:30});
                        location.href = location.href;
                    }
                    else{
                        ERRORSHOW.inputWrong(".reguphone",resouse.desc);
                    }
                }
            });
        }
    });

    //注册密码失去焦点验证
    $(".regupass").blur(function(){
        var $regupass = $(".regupass");
        if($regupass.val().length < 8){
            ERRORSHOW.inputWrong(".regupass","密码长度最少8位！");
            $regupass.addClass("txterror");
            $regupass.focus(function (){
                $(".dias").remove();
                $(".regupass").removeClass("txterror");
            });
        }
    });
    $(".regrpass").blur(function(){
        var $regupass = $(".regupass");
        if($regupass.val().length < 8){
            ERRORSHOW.inputWrong(".regrpass","密码长度最少8位！");
            $regupass.addClass("txterror");
            $regupass.focus(function (){
                $(".dias").remove();
                $(".regrpass").removeClass("txterror");
            });
        }
    });

    //计时器
    function countDown(secs){
        var $getcode = $(".getcode");
        if(--secs>0){
            var vals = secs+"秒后重新获取";
            $getcode.attr("disabled","disabled");
            $getcode.css({"color":"#ababab","border":"#eee 1px solid"});
            $getcode.val(vals);
            setTimeout(function (){
                countDown(secs);
            },1000);
        }else{
            $getcode.val("重新发送");
            $getcode.removeAttr("disabled");
            $getcode.removeAttr("style");
        }
    }
};

var bindPhoneCoundDown = function (e_sec, e_event, e_isbind){
    var $getcode = e_event;
    if(--e_sec > 0){
        var vals = e_sec +"秒 后重新获取";
        $getcode.off('click');
        $getcode.addClass('unlink');
        $getcode.text(vals);
        setTimeout(function (){
            bindPhoneCoundDown(e_sec, $getcode, e_isbind);
        },1000);
    }else{
        $getcode.text("重新发送验证码");
        $getcode.removeClass('unlink');

        var $getCode = $('.js-btn-get-code');
        $getCode.on('click', function (){
            var $phone = $('.js-txt-bind-phone');
            var txt_phone = '';
            if(e_isbind){
                txt_phone = $.trim($phone.val());
            }else{
                txt_phone = window.bind_text_phone;
            }
            if(txt_phone == '' || !txt_phone.match(phonereg)){
                HFErrorShow.inputWrong(".js-txt-bind-phone", '请输入正确的手机号');
            }else{
                $('.errorspan').remove();
                var resouse = window.getCode(txt_phone);
                if(resouse.code == 1){
                    bindPhoneCoundDown(60, $('.js-btn-get-code'));
                }else{
                    HFErrorShow.inputWrong(".js-txt-bind-phone", resouse.desc);
                }
            }
        });
    }
};

var HFErrorShow = {
    inputWrong : function(obj,outtxt){
        $(".dias").remove();
        var html = "<span class='dias errorspan'>"
            +outtxt
            +"</span>";
        $("body").append(html);
        ERRORSHOW.inWrongResize(obj);

        $(window).on("resize",function(){
            console.log("resize");
            HFErrorShow.inWrongResize(obj);
        });
    },
    inWrongResize : function(obj){
        var wd = parseInt($(obj).css("width"));
        var hg = parseInt($(obj).css("height"));
        var lf = parseInt($(obj).offset().left);
        var tp = parseInt($(obj).offset().top + hg);
        $(".errorspan").css({
            "display": "inline-block",
            "width": wd + "px",
            "height": "22px",
            "position": "absolute",
            "left": lf +"px",
            "top": tp +"px",
            "color": "#fa5a67",
            "text-align": "center",
            "z-index": "9900",
            "background": "none",
            "font-size": "14px",
            "line-height": "22px"
        });
    }
};

